package com.itwill.ecom.ordersDetail;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.itwill.ecom.product.ProductBeans;

@Repository("ordersDetailService")
public class OrdersDetailServiceImpl implements OrdersDetailService {
	@Autowired
	private OrdersDetailDao ordersDetailDao;
	
	public OrdersDetailServiceImpl() {
		System.out.println("#### OrdersDetailService() : 기본 생성자");
	}
	
	public OrdersDetailServiceImpl(OrdersDetailDao ordersDetailDao) {
		super();
		System.out.println("#### OrdersDetailService(OrdersDetailDao ordersDetailDao)");
		this.ordersDetailDao = ordersDetailDao;
	}

	public OrdersDetailDao getOrdersDetailDao() {
		return ordersDetailDao;
	}

	public void setOrdersDetailDao(OrdersDetailDao ordersDetailDao) {
		this.ordersDetailDao = ordersDetailDao;
	}
	
	
	//주문 상세를 만들자
	@Override
	public boolean createOrdersDetail(OrdersDetailBeans create) throws Exception{
		boolean result = false;
		
		try{
			ordersDetailDao.create(create);
			result = true;
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return result;
	}
	
	//주문 상세를 검색하자
	@Override
	public List<OrdersDetailBeans> getAll() throws Exception{
		return ordersDetailDao.getAll();
	}
	
	//주문 상세를 주문번호로 검색하자
	@Override
	public OrdersDetailBeans getNo(int no) throws OrdersDetailNotFound,Exception{
		OrdersDetailBeans detail=ordersDetailDao.getNo(no);
		if(detail==null){
			throw new OrdersDetailNotFound("해당 주문번호의 상세정보가 존재하지 않습니다");
		}
		return detail;
	}
	
	//해당 주문의 상세내역리스트를 검색하자
	@Override
	public List<OrdersDetailBeans> getDetail(int orderNo) throws OrdersDetailNotFound,Exception{
		List<OrdersDetailBeans> detail=ordersDetailDao.getDetail(orderNo);
		if(detail==null){
			throw new OrdersDetailNotFound("해당 주문번호의 상세내역리스트가 존재하지 않습니다");
		}
		return detail;
	}
	
	//주문 상세를 삭제하자
	@Override
	public boolean delete(int deleteNo) throws Exception{
		boolean result = false;
		
		try{
			ordersDetailDao.delete(deleteNo);
			result = true;
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return result;
	}
	
	// 주문번호로 삭제하자
	@Override
	public boolean deleteByOno(int o_no) throws Exception{
		boolean result = false;
		
		try{
			ordersDetailDao.deleteDetails(o_no);
			result = true;
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return result;
	}
}
